<template>
  <div class="app-container">
    <el-card style="margin-bottom: 10px">
      <el-form label-width="128px" size="mini">
        <el-form-item label="车辆预调度配置">
          <div style="display: flex; justify-content: space-between">
            <div>
              当车辆距离生产机组<el-input
                style="width: 140px;margin-left: 4px;margin-right: 4px;"
                v-model="list[0].value"
              ></el-input
              >米时，该车辆可预调度
            </div>
            <el-button type="primary" @click="handleSave(0)">保 存</el-button>
          </div>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card style="margin-bottom: 10px">
      <el-form label-width="128px" size="mini">
        <el-form-item label="结算周期配置">
          <div style="display: flex; justify-content: space-between">
            <div>
              <div>
                结算起始时间 每月
                <el-select v-model="list[1].value">
                  <el-option
                    v-for="item in 31"
                    :key="item"
                    :label="item"
                    :value="item"
                  ></el-option>
                </el-select>
                日
              </div>
              <div>
                结算终止时间 次月
                <el-select v-model="list[2].value">
                  <el-option
                    v-for="item in 31"
                    :key="item"
                    :label="item"
                    :value="item"
                  ></el-option>
                </el-select>
                日
              </div>
            </div>
            <span>
              <el-button type="primary" @click="handleSave(2)">保 存</el-button>
            </span>
          </div>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card style="margin-bottom: 10px">
      <el-form label-width="128px" size="mini">
        <el-form-item label="运距自动审核配置">
          <div style="display: flex; justify-content: space-between">
            <div>
              当实际运距>工程距离<el-input
                v-model="list[3].value"
                style="width: 140px;margin-left: 4px;margin-right: 4px;"
              ></el-input
              >%以内，自动审核通过
            </div>
            <div>
              <el-switch
                v-model="list[3].enable"
                style="margin-right: 20px"
              ></el-switch>
              <el-button type="primary" @click="handleSave(3)">保 存</el-button>
            </div>
          </div>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import {
  listBase,
  getBase,
  delBase,
  addBase,
  updateBase,
} from "@/api/service/config-center/more.js";

export default {
  data() {
    return {
      list: [],
    };
  },
  computed: {},
  created() {
    this.getList();
  },
  methods: {
    async handleSave(type) {
      if (type === 2) {
        await updateBase({ id: this.list[1].id, value: this.list[1].value });
        await updateBase({ id: this.list[2].id, value: this.list[2].value });
      } else if (type === 0) {
        await updateBase({
          id: this.list[type].id,
          value: this.list[type].value,
        });
      } else if (type === 3) {
        await updateBase({
          id: this.list[type].id,
          value: this.list[type].value,
          enable: this.list[type].enable,
        });
      }
      this.$message.success("保存成功");
      this.getList();
    },
    getList() {
      listBase().then((res) => {
        this.list = res.data;
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
